package com.yangguang.controller;

import com.yangguang.service.SchoolService;
import com.yangguang.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("school")
@CrossOrigin
public class SchoolController {
    @Autowired
    private SchoolService schoolService;

    @PostMapping("createSchool")
    public Result createSchool(@RequestParam("schoolName") String schoolName, @RequestParam("address") String address) {
        try {
            if (schoolName == null || address == null) {
                return new Result(false, "有参数为空", null);
            }
            boolean b = schoolService.insertSchool(schoolName, address);
            if (b) {
                return new Result(true, "添加成功", null);
            } else {
                return new Result(false, "添加失败", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "后端有异常", null);
        }

    }
}
